part of 'bloc.dart';

sealed class SingleCollectionPageBlocState {}

class DefaultState implements SingleCollectionPageBlocState {
  DefaultState({
    required this.collection,
    required this.collectionLexicalItems,
    required this.knownLexicalItemSelectionPermitted,
    required this.lexicalItemAdditionPermitted,
    required this.collectionLexicalItemProgressPercentMap,
    required this.permittedLexicalItemIds,
    required this.collectionRepetitionProgresses,
    required this.unspecifiedLexicalItemExists,
    required this.collectionExplicitlyDeleted,
    required this.lexicalItemMap,
    required this.collectionListItems,
    this.customLexicalItemDeletionDialogShown = false,
    CollectionDeletionDialogStatusInfo? collectionDeletionDialogStatusInfo,
  }) : collectionDeletionDialogStatusInfo =
            collectionDeletionDialogStatusInfo ?? _hiddenCollectionDeletionDialogStatusInfo;

  final Collection collection;
  final BuiltList<LexicalItem> collectionLexicalItems;
  final bool knownLexicalItemSelectionPermitted;
  final bool lexicalItemAdditionPermitted;
  final BuiltMap<String, int> collectionLexicalItemProgressPercentMap;
  final BuiltSet<String> permittedLexicalItemIds;
  final BuiltList<double>? collectionRepetitionProgresses;
  final bool unspecifiedLexicalItemExists;
  final bool collectionExplicitlyDeleted;
  final BuiltMap<String, LexicalItem> lexicalItemMap;
  final BuiltList<CollectionListItem> collectionListItems;
  final CollectionDeletionDialogStatusInfo collectionDeletionDialogStatusInfo;
  final bool customLexicalItemDeletionDialogShown;

  static CollectionDeletionDialogStatusInfo get _hiddenCollectionDeletionDialogStatusInfo {
    return CollectionDeletionDialogStatusInfo(
      shown: false,
      deletionModes: BuiltList(),
    );
  }

  DefaultState copyWith({
    Collection Function()? collection,
    BuiltList<LexicalItem> Function()? collectionLexicalItems,
    bool Function()? knownLexicalItemSelectionPermitted,
    bool Function()? lexicalItemAdditionPermitted,
    BuiltMap<String, int> Function()? collectionLexicalItemProgressPercentMap,
    BuiltSet<String> Function()? permittedLexicalItemIds,
    BuiltList<double>? Function()? collectionRepetitionProgresses,
    bool Function()? unspecifiedLexicalItemExists,
    bool Function()? collectionExplicitlyDeleted,
    BuiltMap<String, LexicalItem> Function()? lexicalItemMap,
    BuiltList<CollectionListItem> Function()? collectionListItems,
    CollectionDeletionDialogStatusInfo Function()? collectionDeletionDialogStatusInfo,
    bool Function()? customLexicalItemDeletionDialogShown,
  }) {
    return DefaultState(
      collection: collection == null ? this.collection : collection(),
      collectionLexicalItems:
          collectionLexicalItems == null ? this.collectionLexicalItems : collectionLexicalItems(),
      knownLexicalItemSelectionPermitted: knownLexicalItemSelectionPermitted == null
          ? this.knownLexicalItemSelectionPermitted
          : knownLexicalItemSelectionPermitted(),
      lexicalItemAdditionPermitted: lexicalItemAdditionPermitted == null
          ? this.lexicalItemAdditionPermitted
          : lexicalItemAdditionPermitted(),
      collectionLexicalItemProgressPercentMap: collectionLexicalItemProgressPercentMap == null
          ? this.collectionLexicalItemProgressPercentMap
          : collectionLexicalItemProgressPercentMap(),
      permittedLexicalItemIds: permittedLexicalItemIds == null
          ? this.permittedLexicalItemIds
          : permittedLexicalItemIds(),
      collectionRepetitionProgresses: collectionRepetitionProgresses == null
          ? this.collectionRepetitionProgresses
          : collectionRepetitionProgresses(),
      unspecifiedLexicalItemExists: unspecifiedLexicalItemExists == null
          ? this.unspecifiedLexicalItemExists
          : unspecifiedLexicalItemExists(),
      collectionExplicitlyDeleted: collectionExplicitlyDeleted == null
          ? this.collectionExplicitlyDeleted
          : collectionExplicitlyDeleted(),
      lexicalItemMap: lexicalItemMap == null ? this.lexicalItemMap : lexicalItemMap(),
      collectionListItems:
          collectionListItems == null ? this.collectionListItems : collectionListItems(),
      collectionDeletionDialogStatusInfo:
          collectionDeletionDialogStatusInfo?.call() ?? _hiddenCollectionDeletionDialogStatusInfo,
      customLexicalItemDeletionDialogShown: customLexicalItemDeletionDialogShown?.call() ?? false,
    );
  }
}

class KnownLexicalItemSelection implements SingleCollectionPageBlocState {
  const KnownLexicalItemSelection({
    required this.collectionLexicalItemProgressPercentMap,
    required this.unspecifiedLexicalItems,
    required this.selectedLexicalItemIds,
  });

  final BuiltMap<String, int> collectionLexicalItemProgressPercentMap;
  final BuiltList<LexicalItem> unspecifiedLexicalItems;
  final BuiltSet<String> selectedLexicalItemIds;

  KnownLexicalItemSelection copyWith({
    BuiltMap<String, int> Function()? collectionLexicalItemProgressPercentMap,
    BuiltList<LexicalItem> Function()? unspecifiedLexicalItems,
    BuiltSet<String> Function()? selectedLexicalItemIds,
  }) {
    return KnownLexicalItemSelection(
      collectionLexicalItemProgressPercentMap: collectionLexicalItemProgressPercentMap == null
          ? this.collectionLexicalItemProgressPercentMap
          : collectionLexicalItemProgressPercentMap(),
      unspecifiedLexicalItems: unspecifiedLexicalItems == null
          ? this.unspecifiedLexicalItems
          : unspecifiedLexicalItems(),
      selectedLexicalItemIds:
          selectedLexicalItemIds == null ? this.selectedLexicalItemIds : selectedLexicalItemIds(),
    );
  }
}

class LexicalItemRemoval implements SingleCollectionPageBlocState {
  LexicalItemRemoval({
    required this.collectionLexicalItems,
    required this.collectionLexicalItemProgressPercentMap,
    required this.permittedLexicalItemIds,
    required this.selectedLexicalItemIds,
    this.customLexicalItemDeletionDialogShown = false,
    CollectionLexicalItemRemovalDialogStatusInfo? lexicalItemRemovalDialogStatusInfo,
  }) : lexicalItemRemovalDialogStatusInfo =
            lexicalItemRemovalDialogStatusInfo ?? _hiddenLexicalItemRemovalDialogStatusInfo;

  final BuiltList<LexicalItem> collectionLexicalItems;
  final BuiltMap<String, int> collectionLexicalItemProgressPercentMap;
  final BuiltSet<String> permittedLexicalItemIds;
  final BuiltSet<String> selectedLexicalItemIds;
  final CollectionLexicalItemRemovalDialogStatusInfo lexicalItemRemovalDialogStatusInfo;
  final bool customLexicalItemDeletionDialogShown;

  static CollectionLexicalItemRemovalDialogStatusInfo
      get _hiddenLexicalItemRemovalDialogStatusInfo {
    return CollectionLexicalItemRemovalDialogStatusInfo(
      shown: false,
      removalModes: BuiltList(),
    );
  }

  LexicalItemRemoval copyWith({
    BuiltList<LexicalItem> Function()? collectionLexicalItems,
    BuiltMap<String, int> Function()? collectionLexicalItemProgressPercentMap,
    BuiltSet<String> Function()? permittedLexicalItemIds,
    BuiltSet<String> Function()? selectedLexicalItemIds,
    CollectionLexicalItemRemovalDialogStatusInfo Function()? lexicalItemRemovalDialogStatusInfo,
    bool Function()? customLexicalItemDeletionDialogShown,
  }) {
    return LexicalItemRemoval(
      collectionLexicalItems:
          collectionLexicalItems == null ? this.collectionLexicalItems : collectionLexicalItems(),
      collectionLexicalItemProgressPercentMap: collectionLexicalItemProgressPercentMap == null
          ? this.collectionLexicalItemProgressPercentMap
          : collectionLexicalItemProgressPercentMap(),
      permittedLexicalItemIds: permittedLexicalItemIds == null
          ? this.permittedLexicalItemIds
          : permittedLexicalItemIds(),
      selectedLexicalItemIds:
          selectedLexicalItemIds == null ? this.selectedLexicalItemIds : selectedLexicalItemIds(),
      lexicalItemRemovalDialogStatusInfo:
          lexicalItemRemovalDialogStatusInfo?.call() ?? _hiddenLexicalItemRemovalDialogStatusInfo,
      customLexicalItemDeletionDialogShown: customLexicalItemDeletionDialogShown?.call() ?? false,
    );
  }
}

class CustomCollectionRenaming implements SingleCollectionPageBlocState {
  const CustomCollectionRenaming({
    required this.collection,
    required this.collectionLexicalItems,
    required this.knownLexicalItemSelectionPermitted,
    required this.lexicalItemAdditionPermitted,
    required this.collectionLexicalItemProgressPercentMap,
    required this.permittedLexicalItemIds,
    required this.collectionRepetitionProgresses,
    required this.unspecifiedLexicalItemExists,
    this.validationError,
  });

  final CustomCollection collection;
  final BuiltList<LexicalItem> collectionLexicalItems;
  final bool knownLexicalItemSelectionPermitted;
  final bool lexicalItemAdditionPermitted;
  final BuiltMap<String, int> collectionLexicalItemProgressPercentMap;
  final BuiltSet<String> permittedLexicalItemIds;
  final BuiltList<double>? collectionRepetitionProgresses;
  final bool unspecifiedLexicalItemExists;
  final CustomCollectionTitleValidationError? validationError;

  CustomCollectionRenaming copyWith({
    CustomCollection Function()? collection,
    BuiltList<LexicalItem> Function()? collectionLexicalItems,
    bool Function()? knownLexicalItemSelectionPermitted,
    bool Function()? lexicalItemAdditionPermitted,
    BuiltMap<String, int> Function()? collectionLexicalItemProgressPercentMap,
    BuiltSet<String> Function()? permittedLexicalItemIds,
    BuiltList<double>? Function()? collectionRepetitionProgresses,
    bool Function()? unspecifiedLexicalItemExists,
    CustomCollectionTitleValidationError? Function()? validationError,
  }) {
    return CustomCollectionRenaming(
      collection: collection == null ? this.collection : collection(),
      collectionLexicalItems:
          collectionLexicalItems == null ? this.collectionLexicalItems : collectionLexicalItems(),
      knownLexicalItemSelectionPermitted: knownLexicalItemSelectionPermitted == null
          ? this.knownLexicalItemSelectionPermitted
          : knownLexicalItemSelectionPermitted(),
      lexicalItemAdditionPermitted: lexicalItemAdditionPermitted == null
          ? this.lexicalItemAdditionPermitted
          : lexicalItemAdditionPermitted(),
      collectionLexicalItemProgressPercentMap: collectionLexicalItemProgressPercentMap == null
          ? this.collectionLexicalItemProgressPercentMap
          : collectionLexicalItemProgressPercentMap(),
      permittedLexicalItemIds: permittedLexicalItemIds == null
          ? this.permittedLexicalItemIds
          : permittedLexicalItemIds(),
      collectionRepetitionProgresses: collectionRepetitionProgresses == null
          ? this.collectionRepetitionProgresses
          : collectionRepetitionProgresses(),
      unspecifiedLexicalItemExists: unspecifiedLexicalItemExists == null
          ? this.unspecifiedLexicalItemExists
          : unspecifiedLexicalItemExists(),
      validationError: validationError?.call(),
    );
  }
}
